#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Resource, reqparse
from werkzeug.datastructures import FileStorage

from service.workerInfoService import WorkerInfoService
from utils import commons
from flask import jsonify


class WorkerInfoOtherResource(Resource):
    # 获取空闲维修师傅信息
    @classmethod
    def get_freeWorkerInfo(cls):
        result = WorkerInfoService.freeWorkerInfo()
        return jsonify(code=result['code'], message=result['message'], data=result['data'])

    # 查找所有的维修师傅信息
    @classmethod
    def get_all_worker(cls):
        result = WorkerInfoService.get_all_worker_info()
        return jsonify(code=result['code'], message=result['message'], data=result['data'])

    # 添加师傅
    @classmethod
    def add_worker(cls):
        parser = reqparse.RequestParser()
        parser.add_argument("workerName", location="form", required=True, help='workerName属性缺失或参数类型不正确')
        parser.add_argument("workerPhone", location="form", required=True, help='workerPhone属性缺失或参数类型不正确')
        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)
        result = WorkerInfoService.add_worker_info(**kwargs)
        return jsonify(code=result['code'], message=result['message'], data=result['data'])

    # 删除师傅
    @classmethod
    def del_worker(cls):
        # 删除师傅需要传回师傅的workerID
        parser = reqparse.RequestParser()
        parser.add_argument("workerID", location="form", required=True, help='workerID属性缺失或参数类型不正确')
        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)
        result = WorkerInfoService.del_worker_info(**kwargs)
        return jsonify(code=result['code'], message=result['message'], data=result['data'])
